import 'package:flutter/material.dart';
import 'package:sow_app/view/library/classify/classify_tab.dart';
import 'package:sow_app_core/sow_app_core.dart';
import 'package:sow_app_i18n/sow_app_i18n.dart';

import '../../../presenter/state_classify_presenter.dart';

class ClassifyPage extends StatefulWidget {
  const ClassifyPage(
      {Key? key, required this.controller, required this.presenter})
      : super(key: key);
  static const routeName = '/classify';
  final ClassifyController controller;
  final StateClassifyPresenter presenter;
  @override
  State<ClassifyPage> createState() => _ClassifyPageState();
}

class _ClassifyPageState extends State<ClassifyPage> {
  @override
  void initState() {
    widget.presenter.presenterContext = context;
    widget.presenter.presenterSetState = setState;
    Future.delayed(Duration.zero)
        .then((value) => widget.controller.initCatList());

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(I18n.classify),
      ),
      body: DefaultTabController(
        length: 2,
        child: Column(
          children: [
            Align(
              alignment: Alignment.centerLeft,
              child: TabBar(isScrollable: true, tabs: [
                Tab(
                  child: Text(I18n.boy,
                      style: Theme.of(context).textTheme.headline5),
                ),
                Tab(
                  child: Text(I18n.girl,
                      style: Theme.of(context).textTheme.headline5),
                ),
              ]),
            ),
            Expanded(
              child: TabBarView(
                children: [
                  ClassifyTab(
                    classifyList:
                        widget.presenter.allClassifyOptions[WorkDirection.boy]!,
                  ),
                  ClassifyTab(
                    classifyList: widget
                        .presenter.allClassifyOptions[WorkDirection.girl]!,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
